import { TonTplGateway, PutMutiRes, DisableRes, TonTpl, deleteTonTplDto, postTonTplDto, putTonTplDto, PutRes, TonTplInterfaceWithDerive } from "qqlx-core";

import { ViewBase, ViewBaseAction } from "../view-base";
import { TonTplSchema } from "@/river/ton-tpl";

export class ViewTonTpl extends ViewBase<TonTpl> implements ViewBaseAction<TonTpl>, TonTplInterfaceWithDerive<{}> {
  private static instance: ViewTonTpl;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewTonTpl();
    }

    if (!this.instance) this.instance = new ViewTonTpl();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  getSchema(): TonTpl {
    return new TonTplSchema();
  }

  async put() {
    this.pending();
    const dto = { schema: this.data.schema };
    return this.$request.put<putTonTplDto, PutRes<TonTpl>>(TonTplGateway.path, dto);
  }

  async post(dto: postTonTplDto) {
    this.pending();
    return this.$request.post<postTonTplDto, PutMutiRes<TonTpl>>(TonTplGateway.path, dto);
  }

  async delete(dto: deleteTonTplDto) {
    this.pending();
    return this.$request.delete<deleteTonTplDto, DisableRes>(TonTplGateway.path, dto);
  }
}
